package com.hoyo.utils;

import com.alibaba.fastjson.JSONObject;
import com.hoyo.common.AppConstant;
import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;

public class MessageUtils {
	
	public static boolean send(String reciever, String templateCode, String params) throws ApiException{
		TaobaoClient client = new DefaultTaobaoClient(AppConstant.Message.SERVER_URL, AppConstant.Message.APP_KEY, AppConstant.Message.APP_SECRET);
		AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
		req.setSmsType("normal");
		req.setSmsFreeSignName(AppConstant.Message.SIGNATURE_NAME);
		req.setSmsParamString(params);
		req.setRecNum(reciever);
		req.setSmsTemplateCode(templateCode);
		AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
		
		System.out.println(JSONObject.toJSONString(rsp));
		
		return rsp.isSuccess();
	}
}
